package com.woniu.woniuticket.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.woniuticket.entity.Form;
import com.woniu.woniuticket.entity.OrderAllInfo;
import com.woniu.woniuticket.entity.OrderForm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author spirit
 * @since 2020-01-02
 */
public interface OrderMapper extends BaseMapper<OrderForm> {

    @Select("SELECT DISTINCT * FROM order_form " +
            "LEFT JOIN show_session on show_session.show_session_id=order_form.show_session_id " +
            "LEFT JOIN movie on show_session.movie_id=movie.movie_id where student_id = #{id}"
            )
    public List<OrderAllInfo> getOrder(@Param("id")Integer id);

    @Update("update order_form set order_status = 5 where order_id = #{oid}")
    int delOrder(@Param("oid") Integer orderId);

    @Update("update order_form set order_status = 4 where order_id = #{rid}")
    int remoney(@Param("rid") Integer orderId);

    @Update("update order_form set order_status = 3 where order_id = #{qrid}")
    int qrorder(@Param("qrid") Integer orderId);

    @Select("select order_status from order_form where order_id = #{cid}")
    int selectOrder(@Param("cid") Integer orderId);

    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    @Insert("insert into order_form values(0,#{showSessionId},1,#{orderPrice},#{seatId},#{orderTime}," +
            "#{ticketNumber},#{orderNo},#{totelPayment},#{orderName},#{studentId})")
    int productOrder( OrderForm orderForm);

    @Select("select order_no from order_form where order_no = #{on}")
    List<String> findByOrderNo(@Param("on") String out_trade_no);

    @Update("update order_form set order_status = 2 where order_no = #{id}")
    int payMoney(@Param("id") String orderNo);

    @Select("select * from order_form where order_id = #{id}")
    OrderForm findSomeOrder(@Param("id")Integer orderId);

    @Update("update order_form set order_status = 6,seat_id = null where order_id = #{id}")
    int ttlOrder(@Param("id") Integer orderId);

    @Select("select * from order_form where show_session_id=#{showSessionId} and seat_id=#{seatId}")
    OrderForm selectOrderBySeatIdAndShowSessionId(String seatId, Integer showSessionId);


}
